package com.quasar.hpatient.presenter;

import android.content.ContentValues;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.quasar.hpatient.model.httpmodel.AnotherResult;
import com.quasar.hpatient.model.litePalmodel.BaseInfoVersiondb;
import com.quasar.hpatient.model.litePalmodel.BloodTypeInfodb;
import com.quasar.hpatient.model.litePalmodel.DailyItemInfodb;
import com.quasar.hpatient.model.litePalmodel.DefaultInspectioninfodb;
import com.quasar.hpatient.model.litePalmodel.HospitalInfodb;
import com.quasar.hpatient.model.litePalmodel.InspectionDetailInfodb;
import com.quasar.hpatient.model.litePalmodel.InspectionInfodb;
import com.quasar.hpatient.model.litePalmodel.InspectionItemInfodb;
import com.quasar.hpatient.model.litePalmodel.KidneySourceTypedb;
import com.quasar.hpatient.model.litePalmodel.MedicineInfodb;
import com.quasar.hpatient.model.litePalmodel.PositonInfodb;
import com.quasar.hpatient.model.medicalmodel.BaseInfoVersionData;
import com.quasar.hpatient.model.medicalmodel.BloodTypeData;
import com.quasar.hpatient.model.medicalmodel.DailyiteminfoData;
import com.quasar.hpatient.model.medicalmodel.DefaultInspectioninfoData;
import com.quasar.hpatient.model.medicalmodel.HospitalData;
import com.quasar.hpatient.model.medicalmodel.InspectionInfoData;
import com.quasar.hpatient.model.medicalmodel.InspectionItemInfoData;
import com.quasar.hpatient.model.medicalmodel.InspectiondetailinfoData;
import com.quasar.hpatient.model.medicalmodel.KidneySourceTypeData;
import com.quasar.hpatient.model.medicalmodel.MedicineinfoData;
import com.quasar.hpatient.model.medicalmodel.PositionData;
import com.quasar.hpatient.model.requestmodel.RequestModel;
import com.quasar.hpatient.onInterface.AnotherResultListener;
import com.quasar.hpatient.onInterface.OnInfoVersionListener;
import com.vise.log.ViseLog;

import org.litepal.crud.DataSupport;

import java.util.List;

/**
 * author : 许建宏
 * Date: 2018/2/1 0001
 * View:
 */

public class BaseInfoVersionPresenter {

    private OnInfoVersionListener anotherResult;

    private RequestModel requestModel;

    public BaseInfoVersionPresenter(OnInfoVersionListener anotherResult) {
        this.requestModel = new RequestModel();
        this.anotherResult = anotherResult;
    }

    //查询有版本更新的表
    public void seleteTableName() {

        requestModel.CommonBaseInfoVersion(new AnotherResultListener<AnotherResult<BaseInfoVersionData>>() {
            @Override
            public void onSuccess(AnotherResult<BaseInfoVersionData> data) {
                ContrastTableversion(data);
            }

            @Override
            public void onError(String msg) {
                anotherResult.onInfoVersionError(msg);
            }

            @Override
            public void onRefreshUI() {
                anotherResult.onInfoVersionRefreshUI();
            }
        });
    }

    //根据本地的数据表版本进行对比
    public void ContrastTableversion(AnotherResult<BaseInfoVersionData> anotherResult) {

        int num = anotherResult.getList().size();
        for (int i = 0; i < num; i++) {
            BaseInfoVersionData baseInfoVersionData = anotherResult.getList().get(i);
            List<BaseInfoVersiondb> baseInfoVersiondb = DataSupport.where("version < ? and primaryid=?", baseInfoVersionData.getVersion() + "", baseInfoVersionData.getId() + "").find(BaseInfoVersiondb.class);
            if (baseInfoVersiondb.size() > 0) {
                GetQueryAllFromInformation(baseInfoVersiondb.get(0).getName(), baseInfoVersiondb.get(0).getVersion() + "", baseInfoVersionData);
            }
        }
    }


    //更新BaseInfoVersiondb表信息
    public void updateBaseInfoVersion(BaseInfoVersionData baseInfoVersionData) {

        List<BaseInfoVersiondb> baseInfoVersiondb = DataSupport.where("name=?", baseInfoVersionData.getName()).find(BaseInfoVersiondb.class);


        ViseLog.d("需要更新的数据为 id"+baseInfoVersiondb.get(0).getPrimaryid()+"名称"+baseInfoVersiondb.get(0).getName()
        +"版本信息"+baseInfoVersionData.getVersion());
        if (baseInfoVersiondb != null && baseInfoVersiondb.size() > 0) {
            ContentValues values = new ContentValues();
            values.put("version", baseInfoVersionData.getVersion());
            values.put("updateTime", baseInfoVersionData.getUpdateTime() + "");
            DataSupport.update(BaseInfoVersiondb.class, values, baseInfoVersiondb.get(0).getId());
        }

    }


    //获取更新表的信息
    public void GetQueryAllFromInformation(String tableName, String version, final BaseInfoVersionData baseInfoVersion) {

        requestModel.GetQueryAllFromInformationServer(tableName, version, new AnotherResultListener<AnotherResult<Object>>() {
            @Override
            public void onSuccess(AnotherResult<Object> data) {
                transformationData(data, baseInfoVersion);
            }

            @Override
            public void onError(String msg) {

            }

            @Override
            public void onRefreshUI() {

            }
        });
    }


    //解析json并转换成相应的模型
    public void transformationData(AnotherResult<Object> anotherResult, BaseInfoVersionData baseInfoVersionData) {
        String listTxt = JSONArray.toJSONString(anotherResult.getList());
        int updateNum = 0;
        boolean isAddDatanum = false;
        switch (anotherResult.getTableName()) {
            //器官来源表信息
            case "kidneysourcetype":
                List<KidneySourceTypeData> list = JSON
                        .parseArray(listTxt, KidneySourceTypeData.class);
                if (list != null && list.size() > 0) {
                    for (int i = 0; i < list.size(); i++) {
                        List<KidneySourceTypedb> kidneySourceTypedb = DataSupport.where("primaryid=?", list.get(i).getId() + "").find(KidneySourceTypedb.class);
                        ViseLog.d("kidneySourceTypedb有没有数据");
                        if (kidneySourceTypedb != null && kidneySourceTypedb.size() > 0) {
                            ContentValues values = new ContentValues();
                            values.put("Name", list.get(i).getName());
                            values.put("Description", list.get(i).getDescription());
                            values.put("status", list.get(i).getStatus());
                            values.put("version", list.get(i).getVersion());
                            updateNum = DataSupport.update(KidneySourceTypedb.class, values, kidneySourceTypedb.get(0).getPrimaryid());
                            ViseLog.d("kidneySourceTypedb数据进行修改");
                        } else {
                            KidneySourceTypedb kidney = new KidneySourceTypedb(
                                    1,
                                    list.get(i).getId(),
                                    list.get(i).getName(),
                                    list.get(i).getDescription(),
                                    list.get(i).getStatus(),
                                    list.get(i).getVersion()
                            );
                            isAddDatanum = kidney.save();
                        }
                    }
                }
                updateVersion(updateNum,isAddDatanum,baseInfoVersionData);
                break;

            //医院信息
            case "hospitalinfo":

                List<HospitalData> hospitalDataList = JSON
                        .parseArray(listTxt, HospitalData.class);
                if (hospitalDataList != null && hospitalDataList.size() > 0) {
                    for (int i = 0; i < hospitalDataList.size(); i++) {
                        List<HospitalInfodb> hospitalInfodb = DataSupport.where("primaryid=?", hospitalDataList.get(i).getId() + "").find(HospitalInfodb.class);

                        if (hospitalInfodb != null && hospitalInfodb.size() > 0) {
                            ContentValues cv = new ContentValues();
                            cv.put("Name", hospitalDataList.get(i).getName());
                            cv.put("cover", hospitalDataList.get(i).getCover());
                            cv.put("provinceid", hospitalDataList.get(i).getProvinceid());
                            cv.put("cityid", hospitalDataList.get(i).getCityid());
                            cv.put("regionid", hospitalDataList.get(i).getRegionid());
                            cv.put("addr", hospitalDataList.get(i).getAddr());
                            cv.put("officephone", hospitalDataList.get(i).getOfficephone());
                            cv.put("linkman", hospitalDataList.get(i).getLinkman());
                            cv.put("status", hospitalDataList.get(i).getStatus());
                            cv.put("description", hospitalDataList.get(i).getDescription());
                            cv.put("createtime", hospitalDataList.get(i).getCreatetime() + "");
                            cv.put("lastedittime", hospitalDataList.get(i).getLastedittime() + "");
                            cv.put("version", hospitalDataList.get(i).getVersion());
                            updateNum = DataSupport.update(HospitalInfodb.class, cv, hospitalInfodb.get(0).getId());
                        } else {
                            HospitalInfodb hospitalInfoDB = new HospitalInfodb(
                                    1,
                                    hospitalDataList.get(i).getId(),
                                    hospitalDataList.get(i).getName(),
                                    hospitalDataList.get(i).getCover(),
                                    hospitalDataList.get(i).getProvinceid(),
                                    hospitalDataList.get(i).getCityid(),
                                    hospitalDataList.get(i).getRegionid(),
                                    hospitalDataList.get(i).getAddr(),
                                    hospitalDataList.get(i).getOfficephone(),
                                    hospitalDataList.get(i).getLinkman(),
                                    hospitalDataList.get(i).getStatus(),
                                    hospitalDataList.get(i).getDescription(),
                                    hospitalDataList.get(i).getCreatetime(),
                                    hospitalDataList.get(i).getLastedittime(),
                                    hospitalDataList.get(i).getVersion());
                            isAddDatanum = hospitalInfoDB.save();
                        }
                    }
                }
                updateVersion(updateNum,isAddDatanum,baseInfoVersionData);
                break;

            case "dailyiteminfo"://请求日常项目检查项
                List<DailyiteminfoData> dailyiteminfoData = JSON
                        .parseArray(listTxt.toString(), DailyiteminfoData.class);


                ViseLog.d("日常数据更新" + "json" + listTxt);

                if (dailyiteminfoData != null && dailyiteminfoData.size() > 0) {
                    for (int i = 0; i < dailyiteminfoData.size(); i++) {
                        List<DailyItemInfodb> dailyItemInfodb = DataSupport.where("primaryid=?", dailyiteminfoData.get(i).getId() + "").find(DailyItemInfodb.class);

                        //检测是否存在，存在就修改不存在就新增
                        if (dailyItemInfodb != null && dailyItemInfodb.size() > 0) {
                            ContentValues values = new ContentValues();
                            values.put("name", dailyiteminfoData.get(i).getName());
                            values.put("typeid", dailyiteminfoData.get(i).getTypeid());
                            values.put("name_en", dailyiteminfoData.get(i).getName_en());
                            values.put("short_name_en", dailyiteminfoData.get(i).getShort_name_en());
                            values.put("dimensionid", dailyiteminfoData.get(i).getDimensionid());
                            values.put("logType", dailyiteminfoData.get(i).getLogtype());
                            values.put("standard", dailyiteminfoData.get(i).getStandard());
                            values.put("description", dailyiteminfoData.get(i).getDescription());
                            values.put("createTime", dailyiteminfoData.get(i).getCreatetime() + "");
                            values.put("lastEditTime", dailyiteminfoData.get(i).getLastedittime() + "");
                            values.put("status", dailyiteminfoData.get(i).getStatus());
                            values.put("version", dailyiteminfoData.get(i).getVersion());
                            updateNum = DataSupport.update(DailyItemInfodb.class, values, dailyItemInfodb.get(0).getId());
                        } else {
                            DailyItemInfodb dataBean = new DailyItemInfodb(
                                    1,
                                    dailyiteminfoData.get(i).getId(),
                                    dailyiteminfoData.get(i).getName(),
                                    dailyiteminfoData.get(i).getName_en(),
                                    dailyiteminfoData.get(i).getShort_name_en(),
                                    dailyiteminfoData.get(i).getDimensionid(),
                                    dailyiteminfoData.get(i).getLogtype(),
                                    dailyiteminfoData.get(i).getStandard(),
                                    dailyiteminfoData.get(i).getDescription(),
                                    dailyiteminfoData.get(i).getCreatetime(),
                                    dailyiteminfoData.get(i).getLastedittime(),
                                    dailyiteminfoData.get(i).getTypeid(),
                                    dailyiteminfoData.get(i).getStatus(),
                                    dailyiteminfoData.get(i).getVersion()

                            );
                            isAddDatanum = dataBean.save();
                        }
                    }
                }
                updateVersion(updateNum,isAddDatanum,baseInfoVersionData);
                break;

            case "bloodtypeinfo"://血型信息

                List<BloodTypeData> bloodTypeDataList = JSON
                        .parseArray(listTxt, BloodTypeData.class);

                if (bloodTypeDataList != null && bloodTypeDataList.size() > 0) {

                    for (int i = 0; i < bloodTypeDataList.size(); i++) {
                        List<BloodTypeInfodb> bloodTypeData = DataSupport.where("primaryid=?", bloodTypeDataList.get(i).getId() + "").find(BloodTypeInfodb.class);
                        if (bloodTypeData != null && bloodTypeData.size() > 0) {
                            ContentValues cv = new ContentValues();
                            cv.put("name", bloodTypeDataList.get(i).getName());
                            cv.put("description", bloodTypeDataList.get(i).getDescription());
                            cv.put("status", bloodTypeDataList.get(i).getStatus());
                            cv.put("version", bloodTypeDataList.get(i).getVersion());
                            updateNum = DataSupport.update(BloodTypeInfodb.class, cv, bloodTypeData.get(0).getId());
                        } else {
                            BloodTypeInfodb bl = new BloodTypeInfodb(
                                    1,
                                    bloodTypeDataList.get(i).getId(),
                                    bloodTypeDataList.get(i).getName(),
                                    bloodTypeDataList.get(i).getDescription(),
                                    bloodTypeDataList.get(i).getStatus(),
                                    bloodTypeDataList.get(i).getVersion()
                            );
                            isAddDatanum = bl.save();
                        }
                    }
                }
                updateVersion(updateNum,isAddDatanum,baseInfoVersionData);
                break;

            case "positioninfo"://职位信息

                List<PositionData> positionDataList = JSON
                        .parseArray(listTxt, PositionData.class);

                if (positionDataList != null && positionDataList.size() > 0) {
                    for (int i = 0; i < positionDataList.size(); i++) {
                        List<PositonInfodb> positionData1 = DataSupport.where("primaryid=?", positionDataList.get(i).getId() + "").find(PositonInfodb.class);
                        if (positionData1 != null && positionData1.size() > 0) {
                            ContentValues cv = new ContentValues();
                            cv.put("name", positionDataList.get(i).getName());
                            cv.put("pid", positionDataList.get(i).getPid());
                            cv.put("description", positionDataList.get(i).getDescription());
                            cv.put("status", positionDataList.get(i).getStatus());
                            cv.put("version", positionDataList.get(i).getVersion());
                            updateNum = DataSupport.update(PositonInfodb.class, cv, positionData1.get(0).getId());
                        } else {
                            PositonInfodb DB = new PositonInfodb(
                                    1,
                                    positionDataList.get(i).getId(),
                                    positionDataList.get(i).getName(),
                                    positionDataList.get(i).getPid(),
                                    positionDataList.get(i).getDescription(),
                                    positionDataList.get(i).getStatus(),
                                    positionDataList.get(i).getVersion());

                            isAddDatanum = DB.save();
                        }
                    }
                }
                updateVersion(updateNum,isAddDatanum,baseInfoVersionData);
                break;

            case "default_inspectioninfo"://默认检查单信息
                List<DefaultInspectioninfoData> defaultInspectioninfoDataList = JSON
                        .parseArray(listTxt, DefaultInspectioninfoData.class);
                if (defaultInspectioninfoDataList != null && defaultInspectioninfoDataList.size() > 0) {

                    for (int i = 0; i < defaultInspectioninfoDataList.size(); i++) {
                        List<DefaultInspectioninfodb> defaultInspectioninfoData = DataSupport.where("primaryid=?", defaultInspectioninfoDataList.get(i).getId() + "")
                                .find(DefaultInspectioninfodb.class);
                        if (defaultInspectioninfoData != null && defaultInspectioninfoData.size() > 0) {
                            ContentValues values = new ContentValues();
                            values.put("diseaseinfoId", defaultInspectioninfoDataList.get(i).getDiseaseinfoId());
                            values.put("hospitalId", defaultInspectioninfoDataList.get(i).getHospitalId());
                            values.put("inspectioninfoId", defaultInspectioninfoDataList.get(i).getInspectioninfoId());
                            values.put("descripation", defaultInspectioninfoDataList.get(i).getDescripation());
                            values.put("version", defaultInspectioninfoDataList.get(i).getVersion());
                            updateNum = DataSupport.update(DefaultInspectioninfodb.class, values, defaultInspectioninfoData.get(0).getId());
                        } else {
                            DefaultInspectioninfodb defaultInspectioninfoDB = new DefaultInspectioninfodb(
                                    defaultInspectioninfoDataList.get(i).getId(),
                                    defaultInspectioninfoDataList.get(i).getDiseaseinfoId(),
                                    defaultInspectioninfoDataList.get(i).getHospitalId(),
                                    defaultInspectioninfoDataList.get(i).getInspectioninfoId(),
                                    defaultInspectioninfoDataList.get(i).getDescripation(),
                                    defaultInspectioninfoDataList.get(i).getVersion());
                            isAddDatanum = defaultInspectioninfoDB.save();
                        }
                    }
                }
                updateVersion(updateNum,isAddDatanum,baseInfoVersionData);
                break;

            case "inspectiondetailinfo"://检查单详情
                List<InspectiondetailinfoData> inspectiondetailinfoDataList = JSON
                        .parseArray(listTxt, InspectiondetailinfoData.class);

                if (inspectiondetailinfoDataList != null && inspectiondetailinfoDataList.size() > 0) {
                    for (int i = 0; i < inspectiondetailinfoDataList.size(); i++) {
                        List<InspectionDetailInfodb> inspectionDetailInfodb = DataSupport.where("primaryid=?", inspectiondetailinfoDataList.get(i).getId() + "")
                                .find(InspectionDetailInfodb.class);

                        if (inspectionDetailInfodb != null && inspectionDetailInfodb.size() > 0) {
                            ContentValues values = new ContentValues();
                            values.put("inspectionid", inspectiondetailinfoDataList.get(i).getInspectionid());
                            values.put("itemid", inspectiondetailinfoDataList.get(i).getItemid());
                            values.put("version", inspectiondetailinfoDataList.get(i).getVersion());
                            values.put("status", inspectiondetailinfoDataList.get(i).getStatus());
                            values.put("defaultSelect", inspectiondetailinfoDataList.get(i).getDefaultSelect());
                            updateNum = DataSupport.update(InspectionDetailInfodb.class, values, inspectionDetailInfodb.get(0).getId());
                        } else {
                            InspectionDetailInfodb insp = new InspectionDetailInfodb(
                                    1,
                                    inspectiondetailinfoDataList.get(i).getId(),
                                    inspectiondetailinfoDataList.get(i).getInspectionid(),
                                    inspectiondetailinfoDataList.get(i).getItemid(),
                                    inspectiondetailinfoDataList.get(i).getVersion(),
                                    inspectiondetailinfoDataList.get(i).getStatus(),
                                    inspectiondetailinfoDataList.get(i).getDefaultSelect(),
                                    inspectiondetailinfoDataList.get(i).getSort()
                            );
                            isAddDatanum = insp.save();
                        }
                    }
                }
                updateVersion(updateNum,isAddDatanum,baseInfoVersionData);
                break;

            case "inspectioninfo"://检查单信息

                List<InspectionInfoData> infoDataList = JSON
                        .parseArray(listTxt, InspectionInfoData.class);
                if (infoDataList != null && infoDataList.size() > 0) {
                    for (int i = 0; i < infoDataList.size(); i++) {
                        List<InspectionInfodb> inspectionInfodbList = DataSupport.where("primaryid=?", infoDataList.get(i).getId() + "").find(InspectionInfodb.class);

                        if (inspectionInfodbList != null && inspectionInfodbList.size() > 0) {
                            ContentValues values = new ContentValues();
                            values.put("name", infoDataList.get(i).getName());
                            values.put("userId", infoDataList.get(i).getUserId());
                            values.put("userType", infoDataList.get(i).getTypeid());
                            values.put("typeid", infoDataList.get(i).getTypeid());
                            values.put("sort", infoDataList.get(i).getSort());
                            values.put("description", infoDataList.get(i).getDescription());
                            values.put("version", infoDataList.get(i).getVersion());
                            values.put("status", infoDataList.get(i).getStatus());
                            updateNum = DataSupport.update(InspectionInfodb.class, values, inspectionInfodbList.get(0).getId());
                        } else {
                            InspectionInfodb insp = new InspectionInfodb(
                                    1,
                                    infoDataList.get(i).getId(),
                                    infoDataList.get(i).getName(),
                                    infoDataList.get(i).getUserId(),
                                    infoDataList.get(i).getUserType(),
                                    infoDataList.get(i).getTypeid(),
                                    infoDataList.get(i).getSort(),
                                    infoDataList.get(i).getDescription(),
                                    infoDataList.get(i).getVersion(),
                                    infoDataList.get(i).getStatus());
                            isAddDatanum = insp.save();
                        }
                    }
                }
                updateVersion(updateNum,isAddDatanum,baseInfoVersionData);
                break;


            case "inspectioniteminfo"://查询检查单检查项目信息
                List<InspectionItemInfoData> itemInfoDataList = JSON
                        .parseArray(listTxt, InspectionItemInfoData.class);
                if (itemInfoDataList != null && itemInfoDataList.size() > 0) {

                    for (int i = 0; i < itemInfoDataList.size(); i++) {
                        List<InspectionItemInfodb> itemInfodb = DataSupport.where("primaryid=?", itemInfoDataList.get(i).getId() + "").find(InspectionItemInfodb.class);
                        if (itemInfodb != null && itemInfodb.size() > 0) {
                            ContentValues cv = new ContentValues();
                            cv.put("name", itemInfoDataList.get(i).getName());
                            cv.put("name_en", itemInfoDataList.get(i).getName_en());
                            cv.put("short_name_en", itemInfoDataList.get(i).getShort_Name_en());
                            cv.put("dimensionId", itemInfoDataList.get(i).getDimensionId());
                            cv.put("standard", itemInfoDataList.get(i).getStandard());
                            cv.put("critical", itemInfoDataList.get(i).getCritical());
                            cv.put("boundary", itemInfoDataList.get(i).getBoundary());
                            cv.put("description", itemInfoDataList.get(i).getDescription());
                            cv.put("version", itemInfoDataList.get(i).getVersion());
                            cv.put("status", itemInfoDataList.get(i).getStatus());
                            updateNum = DataSupport.update(InspectionItemInfodb.class, cv, itemInfodb.get(0).getId());
                        } else {
                            InspectionItemInfodb inspectionItem = new InspectionItemInfodb(
                                    1,
                                    itemInfoDataList.get(i).getId(),
                                    itemInfoDataList.get(i).getName(),
                                    itemInfoDataList.get(i).getName_en(),
                                    itemInfoDataList.get(i).getShort_Name_en(),
                                    itemInfoDataList.get(i).getDimensionId(),
                                    itemInfoDataList.get(i).getStandard(),
                                    itemInfoDataList.get(i).getCritical(),
                                    itemInfoDataList.get(i).getBoundary(),
                                    itemInfoDataList.get(i).getDescription(),
                                    itemInfoDataList.get(i).getVersion(),
                                    itemInfoDataList.get(i).getStatus());
                            isAddDatanum = inspectionItem.save();
                        }
                    }
                }
                updateVersion(updateNum,isAddDatanum,baseInfoVersionData);
                break;


            case "medicineinfo":

                List<MedicineinfoData> medicineinfoDataList = JSON
                        .parseArray(listTxt, MedicineinfoData.class);
                if (medicineinfoDataList != null && medicineinfoDataList.size() > 0) {
                    for (int i = 0; i < medicineinfoDataList.size(); i++) {

                        List<MedicineInfodb> medicineInfodbs = DataSupport.where("primaryid=?", medicineinfoDataList.get(i).getId() + "").find(MedicineInfodb.class);
                        if (medicineInfodbs != null && medicineInfodbs.size() > 0) {
                            ContentValues values = new ContentValues();
                            values.put("typeid", medicineinfoDataList.get(i).getTypeid());
                            values.put("typename", medicineinfoDataList.get(i).getTypename());
                            values.put("name", medicineinfoDataList.get(i).getName());
                            values.put("cover", medicineinfoDataList.get(i).getCover());
                            values.put("name_en", medicineinfoDataList.get(i).getName_en());
                            values.put("short_name_en", medicineinfoDataList.get(i).getShort_name_en());
                            values.put("doses", medicineinfoDataList.get(i).getDose());
                            values.put("content", medicineinfoDataList.get(i).getContent());
                            values.put("dimension", medicineinfoDataList.get(i).getDimension());
                            values.put("packages", medicineinfoDataList.get(i).getPackages());
                            values.put("usedesc", medicineinfoDataList.get(i).getUsedesc());
                            values.put("description", medicineinfoDataList.get(i).getDescription());
                            values.put("status", medicineinfoDataList.get(i).getStatus());
                            values.put("version", medicineinfoDataList.get(i).getVersion());
                            updateNum = DataSupport.update(MedicineInfodb.class, values, medicineInfodbs.get(0).getId());
                        } else {
                            MedicineInfodb medicineInfoDB = new MedicineInfodb(
                                    1,
                                    medicineinfoDataList.get(i).getId(),
                                    medicineinfoDataList.get(i).getTypeid(),
                                    medicineinfoDataList.get(i).getTypename(),
                                    medicineinfoDataList.get(i).getName(),
                                    medicineinfoDataList.get(i).getCover(),
                                    medicineinfoDataList.get(i).getName_en(),
                                    medicineinfoDataList.get(i).getShort_name_en(),
                                    medicineinfoDataList.get(i).getDose(),
                                    medicineinfoDataList.get(i).getContent(),
                                    medicineinfoDataList.get(i).getDimension(),
                                    medicineinfoDataList.get(i).getPackages(),
                                    medicineinfoDataList.get(i).getUsedesc(),
                                    medicineinfoDataList.get(i).getDescription(),
                                    medicineinfoDataList.get(i).getStatus(),
                                    medicineinfoDataList.get(i).getVersion());

                            isAddDatanum = medicineInfoDB.save();
                        }
                    }
                }
                updateVersion(updateNum,isAddDatanum,baseInfoVersionData);
                break;
        }

    }

    //更新版本表
    public void updateVersion(int updateNum,boolean isAddDatanum,BaseInfoVersionData baseInfoVersionData){
        if (updateNum != 0 || isAddDatanum) {
            updateBaseInfoVersion(baseInfoVersionData);
        }
    }
}
